package com.example.imageswitcher.view

import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.ImageSwitcher
import android.widget.ImageView
import android.widget.ViewSwitcher
import com.bumptech.glide.Glide

/**
 * Created by 舍长 on 2019/5/18
 * describe:
 */
class MyImageSwitcher : ViewSwitcher {

    constructor(context: Context) : super(context) {}


    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}

    fun setImageResource(resid: Int) {
        val image = this.nextView as ImageView
        image.scaleType=ImageView.ScaleType.CENTER_CROP
        val lp = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
        image.layoutParams = lp
        Glide
            .with(this)
            .load(resid)
            .into(image)
        showNext()
    }


    override fun getAccessibilityClassName(): CharSequence {
        return ImageSwitcher::class.java.name
    }
}
